import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:lcapp/basic/local_info.dart';
import 'package:lcapp/model/permission/permission_pop.dart';
import 'package:lcapp/page/drawer_page.dart';

/// 跳转模式
enum SplashContentType {
  newFeature, // 新特性（引导页）----在版本信息有变化的时候
  defaultShow, //默认展示
}

class SplashPage extends StatefulWidget {
  @override
  _SplashPageState createState() => _SplashPageState();
}

class _SplashPageState extends State<SplashPage> {
  int countIndex = 0;
  SplashContentType splashContentType = SplashContentType.defaultShow;

  @override
  void initState() {
    super.initState();
    _statusBar();
    WidgetsBinding.instance.addPostFrameCallback((callback)async {
      if(!AsrLocalInfo.isAgreePermission){
        PermissionPopup.isPermission(context,(){
          _switchRootView();
        });
      }else{
        _switchRootView();
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colors.white,
        body: Stack(
          children: <Widget>[
            Visibility(
              visible: splashContentType == SplashContentType.defaultShow,
              child: Container(
                width: double.infinity,
                height: double.infinity,
                decoration: const BoxDecoration(
                  // 这里设置颜色 跟启动页一致的背景色，以免发生白屏闪烁
                  color: Colors.transparent,
                ),
                child: Image.asset(
                  "assets/icon/launch.png",
                  width: double.infinity,
                  height: double.infinity,
                  fit: BoxFit.fill,
                ),
              ),
            ),
          ],
        ));
  }

  void _switchRootView() async {
    Navigator.pushAndRemoveUntil(context, PageRouteBuilder(
        settings: RouteSettings(name: "index"),
        pageBuilder:
        (BuildContext context, Animation animation,
        Animation secondaryAnimation) {
      return DrawerPage();
    }), (route) => false);
  }

  //状态栏
  void _statusBar() {
    //黑色沉浸式状态栏，基于SystemUiOverlayStyle.dark修改了statusBarColor
    if (Platform.isAndroid) {
      SystemUiOverlayStyle uiOverlayStyle = const SystemUiOverlayStyle(
        systemNavigationBarColor: Color(0xFFffffff),
        systemNavigationBarDividerColor: null,
        statusBarColor: Colors.transparent,
        systemNavigationBarIconBrightness: Brightness.light,
        statusBarIconBrightness: Brightness.dark,
        statusBarBrightness: Brightness.light,
      );
      SystemChrome.setSystemUIOverlayStyle(uiOverlayStyle);
    } else {
      SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: SystemUiOverlay.values);
    }
  }
}
